﻿using ConfigServices;
using LogServices;
using MailServices;
using Microsoft.Extensions.DependencyInjection;

namespace MailSender
{
    internal class Program
    {
        static void Main(string[] args)
        {
            ServiceCollection services = new ServiceCollection();
            //1、从环境变量获取
            services.AddScoped<IConfigService, EnvVarConfigService>();
            //2、从配置文件获取
            //services.AddScoped(typeof(IConfigService), s => new IniFileConfigService { FilePath = "mail.ini" });
            services.AddIniFileConfig("mail.ini");
            services.AddLayerdConfig();
            services.AddScoped<IMailServices, MailService>();
            //services.AddScoped<ILogProvider, ConsoleLogProvider>();
            //利用扩展方法，提供Addxxx方法，能够自动出来
            services.AddConsoleLog();

            using (var sp = services.BuildServiceProvider())
            {
                //第一个根对象只能用ServiceLocator
                IMailServices t = sp.GetRequiredService<IMailServices>();
                t.Send("1", "2@qq.com", "2");
            }
        }
    }
}